#pragma once

class WMOModel;

class WMOGroup : public IGraphicsTask
{
	std::vector<MOBA> mBatches;
	MOGP m_header;
	CMpqFile* m_file;
	ui32 LoadChunk(ui32& sig, ui32& len);
	MOVI* m_indices;
	Vertex3F* m_vertices;
	Vertex2F* m_texcoords;
	ui32 m_ofsPY, m_lenPY;
	FileBuffer* m_buffer;
	bool mIsLoaded;

	Mesh** m_meshes;
	Texture** m_textures;
	void LoadBatches();

	std::string m_szFileName;

	WMOModel* m_pParent;
	bool execute();
	void finish() { }
public:
	WMOGroup(std::string szBaseName, ui32 numGroup, WMOModel* pParent);
	bool Init();
	void Draw()
	{
		if(!mIsLoaded)
			return;

		sD3D->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
		for(ui32 i = 0; i < (m_header.numBatchesA + m_header.numBatchesB + m_header.numBatchesC); ++i)
		{
			if(m_meshes[i])
			{
				if(m_textures[i])
					sD3D->SetTexture(0, *(m_textures[i]));
				m_meshes[i]->Draw();
				sD3D->SetTexture(0, 0);
			}
		}
		sD3D->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	}
	void Save();
};